<template>
  <div class="theory">
    <div class="theory_top" v-if="wu">
      <div class="title">
        <div class="t_top">年度党建知识</div>
        <div class="t_bom">
          <div class="m_lef">
            <el-icon style="cursor: pointer" @click="zuo">
              <ArrowLeft />
            </el-icon>
            <div class="tet">{{ month }}<text class="yue">月</text></div>
            <el-icon style="cursor: pointer" @click="you">
              <ArrowRight />
            </el-icon>
          </div>
          <div class="m_ri">理论之星</div>
        </div>
      </div>
      <div :class="myge == 1 ? 'con' : 'con1'" v-if="myge <= 3">
        <div
          class="t_item"
          v-for="(item, i) in data"
          :key="i"
          style="cursor: pointer"
          @click="maskopen(item.url)"
        >
          <div v-if="myge == 1">
            <div v-if="i <= 11">
              <img :src="item.cover" alt="" />
              <div class="xm">{{ item.name }}</div>
              <div class="zd">{{ item.dept }}</div>
            </div>
          </div>
          <div v-if="myge == 2">
            <div v-if="i >= 12 && i <= 23">
              <img :src="item.cover" alt="" />
              <div class="xm">{{ item.name }}</div>
              <div class="zd">{{ item.dept }}</div>
            </div>
          </div>
          <div v-if="myge == 3">
            <div v-if="i >= 24 && i <= 35">
              <img :src="item.cover" alt="" />
              <div class="xm">{{ item.name }}</div>
              <div class="zd">{{ item.dept }}</div>
            </div>
          </div>
          <div v-if="myge == 4">
            <div v-if="i >= 36 && i <= 47">
              <img :src="item.cover" alt="" />
              <div class="xm">{{ item.name }}</div>
              <div class="zd">{{ item.dept }}</div>
            </div>
          </div>
          <div v-if="myge == 5">
            <div v-if="i >= 48 && i <= 50">
              <img :src="item.cover" alt="" />
              <div class="xm">{{ item.name }}</div>
              <div class="zd">{{ item.dept }}</div>
            </div>
          </div>
        </div>
      </div>
      <div class="con2" v-else>
        <div
          class="t_item"
          v-for="(item, i) in data"
          :key="i"
          style="cursor: pointer"
          @click="maskopen(item.url)"
        >
          <div v-if="myge == 1">
            <div v-if="i <= 11">
              <img :src="item.cover" alt="" />
              <div class="xm">{{ item.name }}</div>
              <div class="zd">{{ item.dept }}</div>
            </div>
          </div>
          <div v-if="myge == 2">
            <div v-if="i >= 12 && i <= 23">
              <img :src="item.cover" alt="" />
              <div class="xm">{{ item.name }}</div>
              <div class="zd">{{ item.dept }}</div>
            </div>
          </div>
          <div v-if="myge == 3">
            <div v-if="i >= 24 && i <= 35">
              <img :src="item.cover" alt="" />
              <div class="xm">{{ item.name }}</div>
              <div class="zd">{{ item.dept }}</div>
            </div>
          </div>
          <div v-if="myge == 4">
            <div v-if="i >= 36 && i <= 47">
              <img :src="item.cover" alt="" />
              <div class="xm">{{ item.name }}</div>
              <div class="zd">{{ item.dept }}</div>
            </div>
          </div>
          <div v-if="myge == 5">
            <div v-if="i >= 48 && i <= 50">
              <img :src="item.cover" alt="" />
              <div class="xm">{{ item.name }}</div>
              <div class="zd">{{ item.dept }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="wu" v-else>
      <img src="@/image/wu.png" alt="" />
      <div class="tex">目前还没有理论之星</div>
    </div>
    <!-- 遮罩层 -->
    <div class="mask" v-if="msk">
      <div class="mmm">
        <div class="cuo" style="cursor: pointer" @click="cuo">x</div>
        <video :src="vido" controls autoplay loop class="vido">
          您的浏览器不支持视频标签。
        </video>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { gettheoryApi, gettheoryApi1 } from '@/api/user'
import { ref } from 'vue'
const msk = ref(false)
const vido = ref()
const maskopen = (url: any) => {
  msk.value = true
  vido.value = url
  clearInterval(intervalId.value)
}
const cuo = () => {
  msk.value = false
  setInter()
}
const intervalId: any = ref()
const setInter = () => {
  intervalId.value = setInterval(() => {
    myge.value++
    if (myge.value > ge.value) {
      myge.value = 1
    }
  }, 3000)
}
setInter()
const wu = ref(true)
const data = ref()
const ge: any = ref()
const myge: any = ref(1)
let date = new Date() // 创建一个Date对象，表示当前日期和时间
let mmm: any = date.getMonth()
let year: any = date.getFullYear()
let year1: any = date.getFullYear()
let month: any = date.getMonth() // getMonth()方法返回的月份是从0开始的，所以我们需要加1
const calendar = ref()
gettheoryApi1().then(res => {
  console.log(res, '我的')
  calendar.value = res.data.data.calendar
  // ge.value = res.data.data.data.length
  if (calendar.value == '') {
    gettheory()
  } else {
    data.value = res.data.data.data
    if (data.value.length == 0) {
      wu.value = false
    }
    ge.value = Math.ceil(res.data.data.data.length / 12)
    let aa = res.data.data.calendar.split('-')[1]
    if (aa < 10) {
      month = aa.split('')[1]
    } else {
      month = aa
    }
    // month.value = res.data.data.calendar.split('-')
    console.log(month, '月份')
  }
})

const gettheory = () => {
  let aa: any = ref()
  aa = month
  if (month < 10) {
    aa = '0' + month
  }
  // aa = '02'
  console.log(`${year + '-' + aa}`)

  gettheoryApi(`${year + '-' + aa}`).then(res => {
    data.value = res.data.data.data
    if (data.value.length == 0) {
      wu.value = false
    }
    ge.value = Math.ceil(res.data.data.data.length / 12)
    console.log(ge.value)
    console.log(res)
  })
}

const zuo = () => {
  month = month - 1
  if (month <= 0) {
    month = 12
    year = year - 1
  }
  gettheory()
}
const you = () => {
  if (year == year1 && month < mmm) {
    month = month + 1
    gettheory()
  } else if (year < year1) {
    if (month < 12) {
      month = month + 1
    } else {
      month = 1
      year = year + 1
    }
    gettheory()
  }
}
</script>

<style lang="scss" scoped>
.wu {
  padding-top: 100px;
  text-align: center;

  img {
    width: 236px;
    height: 236px;
  }

  .tex {
    font-size: 24px;
    color: #ffde91;
  }
}

.mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);

  .mmm {
    position: relative;
    width: 968px;
    height: 544px;
    margin: 0 auto;
    margin-top: 30px;

    .vido {
      width: 968px;
      height: 544px;
    }

    .cuo {
      cursor: pointer;
      position: absolute;
      right: 10px;
      font-size: 30px;
      color: #fff;
      z-index: 99;
    }
  }
}

// @media (min-width: 2160px) {
//   .theory {
//     // position: fixed;
//     top: 0;
//     left: 0;
//     width: 100%;
//     height: 100vh;
//     background-image: url('@/image/理论.jpg');
//     background-position: center center;
//     background-repeat: no-repeat;
//   }

//   .theory_top {
//     width: 100%;
//     margin: 0 auto;
//   }

//   .title {
//     padding-top: 500px;
//     // margin-top: 500px;
//     margin-left: 108px;
//     color: #ffc400;
//   }
// }

// @media (max-width: 2159px) {
.theory {
  // position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 1920px;
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  background-image: url('@/image/理论.jpg');
  // background-position: center center;
  // background-repeat: no-repeat;
}

.theory_top {
  width: 1080px;
  margin: 0 auto;
}

.title {
  padding-top: 200px;
  // margin-top: 500px;
  margin-left: 108px;
  color: #ffc400;
}
// }

.con2 {
  display: flex;
  flex-wrap: wrap;
  margin-top: -140px;

  .t_item {
    margin-right: 72px;
    display: flex;
    // justify-content: center;
    // align-items: center;
    flex-direction: column;
    margin-bottom: 70px;

    img {
      width: 184px;
      height: 285px;
      border-radius: 12px;
      border: 1px solid #ffc400;
    }

    .xm {
      font-size: 24px;
      font-weight: 600;
      color: #ffffff;
      margin: 23px 0 14px 0;
    }

    .zd {
      font-size: 16px;
      font-weight: 600;
      color: #ffffff;
    }
  }

  .t_item:nth-child(12n + 1) {
    margin-left: 100px;
  }

  // .t_item:nth-child(13) {
  //   margin-left: 100px;
  // }

  .t_item:nth-child(4n) {
    margin-right: 0;
  }

  .t_item:nth-child(12n + 9) {
    margin-left: 100px;
  }

  .t_item:nth-child(25) {
    margin-left: -575px;
  }

  .t_item:nth-child(49) {
    margin-left: -575px;
  }
}

.con1 {
  display: flex;
  flex-wrap: wrap;
  margin-top: -70px;

  .t_item {
    margin-right: 72px;
    display: flex;
    // justify-content: center;
    // align-items: center;
    flex-direction: column;
    margin-bottom: 70px;

    img {
      width: 184px;
      height: 285px;
      border-radius: 12px;
      border: 1px solid #ffc400;
    }

    .xm {
      font-size: 24px;
      font-weight: 600;
      color: #ffffff;
      margin: 23px 0 14px 0;
    }

    .zd {
      font-size: 16px;
      font-weight: 600;
      color: #ffffff;
    }
  }

  .t_item:nth-child(12n + 1) {
    margin-left: 100px;
  }

  // .t_item:nth-child(13) {
  //   margin-left: 100px;
  // }

  .t_item:nth-child(4n) {
    margin-right: 0;
  }

  .t_item:nth-child(12n + 9) {
    margin-left: 100px;
  }

  .t_item:nth-child(25) {
    margin-left: -575px;
  }
}

.con {
  display: flex;
  flex-wrap: wrap;

  .t_item {
    margin-right: 72px;
    display: flex;
    // justify-content: center;
    // align-items: center;
    flex-direction: column;
    margin-bottom: 70px;

    img {
      width: 184px;
      height: 285px;
      border-radius: 12px;
      border: 1px solid #ffc400;
    }

    .xm {
      font-size: 24px;
      font-weight: 600;
      color: #ffffff;
      margin: 23px 0 14px 0;
    }

    .zd {
      font-size: 16px;
      font-weight: 600;
      color: #ffffff;
    }
  }

  .t_item:nth-child(12n + 1) {
    margin-left: 100px;
  }

  // .t_item:nth-child(13) {
  //   margin-left: 100px;
  // }

  .t_item:nth-child(4n) {
    margin-right: 0;
  }

  .t_item:nth-child(12n + 9) {
    margin-left: 100px;
  }

  // .t_item:nth-child(9) {
  //   margin-bottom: 0;
  // }
  // .t_item:nth-child(10) {
  //   margin-bottom: 0;
  // }

  // .t_item:nth-child(11) {
  //   margin-bottom: 0;
  // }

  // .t_item:nth-child(12) {
  //   margin-bottom: 0;
  // }
}

.title {
  .t_bom {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    margin-bottom: 38px;

    .m_ri {
      font-size: 70px;
      font-weight: normal;
      text-shadow: 0px 4px 10px #e02020;
      margin-right: 123px;
    }

    .m_lef {
      margin-top: 24px;
      display: flex;

      .el-icon {
        color: #fff;
        font-size: 16px;
        margin-top: 30px;
      }

      .tet {
        margin: 0 24px;
        font-size: 70px;
        color: #fff;

        .yue {
          font-size: 24px;
        }
      }
    }
  }

  .t_top {
    font-size: 56px;
    font-weight: normal;
    text-shadow: 0px 4px 10px #e02020;
  }
}
</style>
